<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }

  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }

  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell.minpad {
    padding-right: 10px !important;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
  }

  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }

  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .rj-wrap {
    background: #eee;
    overflow: auto;
    overflow-x: hidden
  }
  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }
  .top-area {
    position: relative;
    margin: 20px 15px;
  }
  .top-area a, .top-area p {
    position: absolute;
    right: 0;
  }
  .top-area .cash {
    text-align: left;
    font-size: 12px;
  }
  .top-area .cash .cny {
    font-size: 40px;
    color: red;
  }
  .divideline {
    background: #eee;
    height: 2px;
  }

  .sellform >>> .weui-form-preview__hd .weui-form-preview__value {
    font-size: 1.2em;
    padding-right: 20px;
  }
  .sellform >>> .weui-cells {
    margin-top: 0;
    background: #e3e3e3;
  }
  .sellform >>> .weui-loadmore__tips {
    background: #e3e3e3;;
  }
  .sellform >>> .weui-loadmore {
    margin-bottom: 0;
  }
  .rj-cell-child.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell-child label {
    color: #333;
    font-size: 14px;
  }
  .rj-cell-child span {
    padding-left: 20px;
    font-size: 14px;
    color: #333;
  }
  .rj-cell-child .tip {
    font-size: 16px;
    color: #333;
  }
  .rj-cell-child i {
    font-size: 18px;
    font-style: normal;
    color: #333;
  }
  .weui-form-preview__ft .weui-form-preview {
    background: #f5f5ef;
  }

  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-panel__bd {
    text-align: left;
  }
  .datalist {
    background: #e3e3e3;
    height: 100%;
    overflow: hidden;
  }
  .datalist.nodata {
    font-size: 14px;
    padding: 5px;
  }

  .weui-media-box_appmsg .weui-media-box__hd {
    font-size: 12px;
    width: 50px;
    height: 50px;
    line-height: 50px;
    border-radius: 50%;
    background: #ccc;
    color: #fff;
  }
  .weui-media-box_appmsg .weui-media-box__hd.yellow {
    background: rgb(255, 215, 0);
  }
  .weui-media-box__desc {
    font-size: 12px;
  }
  .weui-media-box__title {
    white-space: normal;
    font-size: 14px;
    margin-bottom: 5px;
  }
  .weui-form-preview__bd {
    text-align: left;
  }

  .weui-form-preview {
    position: relative;
    background-color: #fff;
    margin: 1%;
    border-radius: 5px;
  }
  .time {
    position: absolute;
    right: 0;
    top: 0;
    font-size: 10px;
    color: #ccc;
  }

  .attachimg {
    width: 14px;
    height: 14px;
  }
  .datalist {
    background: #e3e3e3;
    height: 100%;
    overflow: hidden;
  }
  .datalist.nodata {
    font-size: 14px;
    padding: 5px;
  }
  .weui-media-box {
    padding: 5px;
  }
</style>
<template>
  <div class="viewcustomer">
    <div class="rj-wrap">
      客户详情
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <div class="weui-tab">
      <div class="weui-navbar">
        <div class="weui-navbar__item" :class="{ 'weui-bar__item_on': currentTab == 1 }" @click="switchTab(1)">
          基本信息
        </div>
        <div class="weui-navbar__item" :class="{ 'weui-bar__item_on': currentTab == 2 }" @click="switchTab(2)">
          应收账款
        </div>
        <div class="weui-navbar__item" :class="{ 'weui-bar__item_on': currentTab == 3 }" @click="switchTab(3)">
          预收款
        </div>
      </div>
      <div class="weui-tab__bd">
        <div id="tab1" class="weui-tab__bd-item" :class="{ 'weui-tab__bd-item--active': currentTab == 1 }" >
          <div class="weui-panel weui-panel_access">
            <div class="weui-panel__bd">
              <div class="weui-form-preview billitem rj-cont-tit">
                <div class="rj-cell max">
                  <label>名称：</label>
                  <span>{{customer.name}}</span>
                </div>
                <div class="rj-cell max">
                  <label>地址：</label>
                  <span>{{customer.province + customer.city + customer.district}} {{customer.address}}</span>
                </div>
                <div class="rj-cell max">
                  <label>商务联系人：</label>
                  <span>{{customer.manager}}</span>
                  <span>{{customer.managertel}}</span>
                </div>
                <div class="rj-cell max minpad">
                  <label>收货联系人：</label>
                  <span>{{customer.contact}}</span>
                  <span>{{customer.contactno}}</span>
                  <span>{{customer.memail}}</span>
                </div>
                <div class="rj-cell max minpad">
                  <label>财务联系人：</label>
                  <span>{{customer.financer}}</span>
                  <span>{{customer.fintel}}</span>
                  <span>{{customer.finemail}}</span>
                </div>
                <div class="rj-cell max">
                  <label>注册资金：</label>
                  <span>{{customer.registcapital}} 万元</span>
                </div>
                <div class="rj-cell max">
                  <label>状态：</label>
                  <span>{{customer.statusname}}</span>
                </div>
                <div class="rj-cell">
                  <label>备注：</label>
                  <span style="color: #000;">{{customer.remark}}</span>
                </div>
                <div class="rj-cell max">
                  <label>创建人：</label>
                  <span>{{customer.operator}}</span>
                </div>
                <div class="rj-cell max">
                  <label>创建时间：</label>
                  <span>{{customer.createtime}}</span>
                </div>
              </div>
            </div>
            <div class="weui-panel__hd" v-if="financeinfo != ''">财务信息</div>
            <div class="weui-panel__bd" v-if="financeinfo != ''">
              <div class="weui-form-preview billitem rj-cont-tit">
                <div class="rj-cell max">
                  <label>统一社会信用代码：</label>
                  <span>{{financeinfo.creditCode}}</span>
                </div>
                <div class="rj-cell max">
                  <label>账号：</label>
                  <span>{{financeinfo.cardcode}}</span>
                </div>
                <div class="rj-cell max">
                  <label>账户名称：</label>
                  <span>{{financeinfo.cardname}}</span>
                </div>
                <div class="rj-cell max">
                  <label>开户行：</label>
                  <span>{{financeinfo.bankname}}</span>
                </div>
                <div class="rj-cell max">
                  <label>开票类型：</label>
                  <span>{{financeinfo.invoicingtypename}}</span>
                </div>
                <div class="rj-cell max">
                  <label>开票地址：</label>
                  <span>{{financeinfo.address}}</span>
                </div>
                <div class="rj-cell max">
                  <label>开票电话：</label>
                  <span>{{financeinfo.invoicingtel}}</span>
                </div>
                <div class="rj-cell max">
                  <label>营业执照号：</label>
                  <span>{{financeinfo.licensecode}}</span>
                </div>
<!--                <div class="rj-cell max">-->
<!--                  <label>组织机构代码号：</label>-->
<!--                  <span>{{financeinfo.orgcode}}</span>-->
<!--                </div>-->
                <div class="rj-cell max">
                  <label>备注：</label>
                  <span>{{financeinfo.remark}}</span>
                </div>
                <div class="rj-cell max">
                  <label>开票电话：</label>
                  <span>{{financeinfo.invoicingtel}}</span>
                </div>
                <div class="rj-cell max">
                  <label>创建人：</label>
                  <span>{{financeinfo.operator}}</span>
                </div>
                <div class="rj-cell max">
                  <label>创建时间：</label>
                  <span>{{financeinfo.createtime}}</span>
                </div>
              </div>
            </div>
            <div class="weui-panel__hd" v-if="baseinfo != ''">经营信息</div>
            <div class="weui-panel__bd" v-if="baseinfo != ''">
              <div class="weui-form-preview billitem rj-cont-tit">
                <div class="rj-cell max">
                  <label>经营品类：</label>
                  <span>{{baseinfo.category}}</span>
                </div>
                <div class="rj-cell max">
                  <label>经营品类：</label>
                  <span>{{baseinfo.category}}</span>
                  <span>{{baseinfo.drivername}}</span>
                  <span>{{baseinfo.driverphone}}</span>
                </div>
                <div class="rj-cell max">
                  <label>保险库面积：</label>
                  <span>{{baseinfo.warehousearea}} ㎡</span>
                </div>
                <div class="rj-cell max">
                  <label>配送车数量：</label>
                  <span>{{baseinfo.truckcount}}</span>
                </div>
                <div class="rj-cell max">
                  <label>年度销售目标：</label>
                  <span>{{baseinfo.saletarget}}</span>
                </div>
                <div class="rj-cell max">
                  <label>备注：</label>
                  <span>{{baseinfo.remark}}</span>
                </div>
                <div class="rj-cell max">
                  <label>创建人：</label>
                  <span>{{baseinfo.operator}}</span>
                </div>
                <div class="rj-cell max">
                  <label>创建时间：</label>
                  <span>{{baseinfo.createtime}}</span>
                </div>
              </div>
            </div>
          </div>

        </div>
        <div id="tab2" class="weui-tab__bd-item" :class="{ 'weui-tab__bd-item--active': currentTab == 2 }">
          <div class="banlan_panel">
            <div class="top-area">
<!--              <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary">支付</a>-->
              <div class="cash">总金额：<span style="font-size: 20px;color:red;">{{getMoneyMark(baseinfo.currency)}}</span><span class="cny">{{customer.recbalance}}</span></div>
            </div>
            <div class="divideline"></div>
            <div class="weui-cells__title" style="text-align: left;">充值记录:</div>
            <div class="datalist" v-if="recivflows != ''">
              <div class="weui-form-preview" v-for="(item, index) in recivflows">
                <div class="weui-form-preview__bd">
                  <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
                    <div class="weui-media-box__hd yellow" style="overflow: hidden;">
                      <img src="@/assets/icon-moneybag.png" style="width: 24px; vertical-align: middle;" />
                    </div>
                    <div class="weui-media-box__bd" style="position: relative;">
                      <h4 class="weui-media-box__title">{{item.typename}} [{{item.code}}]<span style="color: #333;float: right;font-size: 16px;">{{item.recbalance}}</span></h4>
                      <p class="weui-media-box__desc">{{item.operator}}  {{item.createtime}}<span style="float: right;font-size: 14px;color: red;">{{item.amount}}</span></p>
                    </div>
                  </a>
                </div>
              </div>
            </div>
            <div class="datalist nodata" v-else>没有充值记录哦！</div>
          </div>
        </div>
        <div id="tab3" class="weui-tab__bd-item" :class="{ 'weui-tab__bd-item--active': currentTab == 3 }">
          <div class="banlan_panel">
            <div class="top-area">
              <p style="bottom: 70px;font-size: 12px;right: 45px;">充值:</p>
              <a href="javascript:;" v-show="permissions.indexOf(2) > -1" class="weui-btn weui-btn_mini weui-btn_primary" style="bottom: 35px;" @click="recharge(1)">货&nbsp;&nbsp;&nbsp;币</a>
              <a href="javascript:;" v-show="permissions.indexOf(2) > -1" class="weui-btn weui-btn_mini weui-btn_primary" style="bottom: 0;" @click="recharge(2)">非货币</a>
              <div class="cash">余额 <span style="font-size: 20px;color:red;">{{getMoneyMark(baseinfo.currency)}}</span><span class="cny">{{customer.prebalance != '' ? customer.prebalance : 0}}</span></div>
              <div class="cash">货币预收款余额 <span style="font-size: 20px;color:red;">{{getMoneyMark(baseinfo.currency)}}{{customer.currPrebalance != '' ? customer.currPrebalance : 0}}</span></div>
              <div class="cash">非货币预收款余额 <span style="font-size: 20px;color:red;">{{getMoneyMark(baseinfo.currency)}}{{customer.nocurrPrebalance != '' ? customer.nocurrPrebalance : 0}}</span></div>
            </div>
            <div class="divideline"></div>
            <div class="weui-cells__title" style="text-align: left;">充值记录:</div>
            <div class="datalist" v-if="cashflows != ''">
              <div class="weui-form-preview" v-for="(item, index) in cashflows">
                <div class="weui-form-preview__bd">
                  <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
                    <div class="weui-media-box__hd yellow" style="overflow: hidden;">
                      <img src="@/assets/icon-moneybag.png" style="width: 24px; vertical-align: middle;" />
                    </div>
                    <div class="weui-media-box__bd" style="position: relative;">
                      <h4 class="weui-media-box__title">{{item.typename}} [{{item.code}}]<span style="color: #333;float: right;font-size: 16px;">{{item.prebalance}}</span></h4>
                      <p class="weui-media-box__desc">{{item.operator}}  {{item.createtime}}<span style="float: right;font-size: 14px;color: red;">{{item.amount}}</span></p>
                    </div>
                  </a>
                </div>
              </div>
            </div>
            <div class="datalist nodata" v-else>没有充值记录哦！</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

  export default {
    name: 'ViewCustomer',
    data() {
      return {
        id: '',
        customer: '',
        baseinfo: '',
        financeinfo: '',
        currentTab: 1,
        recivflows: '',
        cashflows: '',
        permissions: [],
      }
    },
    created() {

    },
    mounted() {
      this.id = this.$route.query.id;
      this.getCustomer(this.id);
      this.getPermission();
    },
    watch: {

    },
    methods: {
      getPermission: function() {
        this.axios({
          method: 'get',
          params:{opttype:13},
          url: '/produce/OperatorPermission!getOperPerm.action',
        }).then((response) => {
          if (response.data.msg == 'success') {
            this.$nextTick(() => {
              this.permissions = response.data.permission.map(item => {
                return item.permission;
              });
            })
          } else {
            this.toastText("获取权限数据失败");
          }

        })
      },
      getCustomer: function (id) {
        this.axios({
          method: 'get',
          url: '/sales/Customer!detail.action',
          params: {customerid: id}
        }).then(response => {
          if (response.data.msg == 'success') {
            let res = response.data;
            // this.customer = res;
            this.customer = res.customer;
            this.baseinfo = res.customer.baseinfo != undefined ? res.customer.baseinfo : {};
            this.financeinfo = res.customer.financeinfo != undefined ? res.customer.financeinfo : {};
            this.recivflows = res.customer.receivableflows != undefined ? res.customer.receivableflows : {};
            this.cashflows = res.customer.cashflows != undefined ? res.customer.cashflows : {};

          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastError('系统错误');
        }
        });
      },
      switchTab(index) {
        this.currentTab = index;
      },
      typename(type) {
        let name = '';
        switch (type) {
          case 1:
            name = '货币';
            break;
          case 2:
            name = '非货币';
            break;
          case 3:
            name = '支付货款';
            break;
        }
        return name;
      },
      recharge: function (type) {
        this.$router.push({name: 'Recharge', query: {id: this.id, type: type}});
        // $.prompt({
        //   title: '充值金额',
        //   text: '',
        //   input: 10000,
        //   empty: false, // 是否允许为空
        //   onOK: function (input) {
        //     //点击确认
        //   },
        //   onCancel: function () {
        //     //点击取消
        //   }
        // });
      },
      getTypeMark: function (type) {
        let marker;
        switch (type) {
          case 1:
            marker = '+';
            break;
          case 2:
            marker = '+';
            break;
          case 3:
            marker = '-';
            break;
        }
        return marker;
      },
      getMoneyMark: function (type) {
        return type == 2 ? '$' : '￥';
      }
    }
  }
</script>
